package com.bk.controller.empIndex;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bk.entity.EmployeeInfo;
import com.bk.service.RedisService;
import com.bk.service.empInfo.EmployeeInfoService;
import com.bk.util.ReturnUtil;
import com.bk.util.SerilizableObjectUtil;
import com.bk.vo.EmployeeRoleVo;

@RestController
public class EmployeeInfoController {
	
	@Autowired
	private RedisService redisService;
	
	@Autowired
	private EmployeeInfoService employeeInfoService;

	@PostMapping("/getEmployeeInfo") /** 获取柜员信息 */
	public ReturnUtil<String> getEmployeeInfo() {
		List<String> employeeList=new ArrayList<String>();
		String value = redisService.getValue("employInfo");//获取柜员信息序列
		try {
			Object unserizlize = SerilizableObjectUtil.unserizlize(value);//反序列化
			EmployeeInfo ei=(EmployeeInfo)unserizlize;//强转
			employeeList.add(ei.getEname());
			return new ReturnUtil<String>(200,"柜员信息",employeeList);
		} catch (Exception e) {
			return new ReturnUtil<String>(400,"当前柜员没有登陆",employeeList);
		}
	}
//	@PostMapping("/getEmployeeList")/**获取所有的柜员信息*/
//	public ReturnUtil<EmployeeInfo> getEmployeeList(){
//		ReturnUtil<EmployeeInfo> re=employeeInfoService.getEmployeeList();
//		return re;
//	}
	
	@PostMapping("/getEmployeeRoleVoList")/**获取所有的柜员与角色信息*/
	public ReturnUtil<EmployeeRoleVo> getEmployeeRoleVoList(){
		ReturnUtil<EmployeeRoleVo> re=employeeInfoService.getEmployeeRoleVoList();
		return re;
	}
	
	@PostMapping("/queryEmpInfoByEmpName")/**获取对应柜员名的柜员*/
	public ReturnUtil<EmployeeRoleVo> queryEmpInfoByEmpName(@RequestParam("empName")String empName){
		ReturnUtil<EmployeeRoleVo> re=employeeInfoService.queryEmpInfoByEmpName(empName);
		return re;
	}
	@PostMapping("/editOrAddEmployeeInfo/{flag}")/**编辑或增加柜员信息  0是编辑  1是增加*/
	public ReturnUtil<EmployeeRoleVo> editOrAddEmployeeInfo(@RequestBody EmployeeRoleVo employeeRoleVo,@PathVariable int flag){
		ReturnUtil<EmployeeRoleVo> re=employeeInfoService.editOrAddEmployeeInfo(employeeRoleVo,flag);
		return re;
	}
	@PostMapping("/deleteEmployeeInfo")/**删除柜员信息*/
	public ReturnUtil<Integer> deleteEmployeeInfo(@RequestParam("empId") String empId){
		ReturnUtil<Integer> re=employeeInfoService.deleteEmployeeInfoByEmpId(empId);
		return re;
	}
	
	
	@PostMapping("/addEmployeeInfo")/**增加柜员信息*/
	public ReturnUtil<EmployeeRoleVo> addEmployeeInfo(@RequestParam("employeeName")String employeeName,@RequestParam("employeePass")String employeePass,@RequestParam("employeeSex")String employeeSex,@RequestParam("empTelephone")String empTelephone,@RequestParam("authorityId")int authorityId){
		ReturnUtil<EmployeeRoleVo> re=employeeInfoService.addEmployeeInfo(employeeName,employeePass,employeeSex,empTelephone,authorityId);
		return re;
	}
}
